# = test.forum.8.rb - Forum , Forum PostFavorites Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# The functionality for different options under Favorites for Sample Forum Post are tested. 
# 
require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'
    
	class TC_ForumPostFavorites_test < Test::Unit::TestCase
    
    def startup      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_navigateToForum
      ie.link(:text, 'Forums').click
      
      assert(ie.link(:text, 'Sample Forum').exists?)
      ie.link(:text, 'Sample Forum').click
    end
    
    def test_07_verifyLinksOnForumPage
      assert(ie.link(:text, 'Save').exists?)
      assert(ie.link(:text, 'Cancel').exists?)
      #assert(ie.link(:id, /ctl00_ctl01$/).exists?)
      #assert(ie.link(:id, /ctl03_ctl01$/).exists?)
      #assert(ie.link(:id, /ctl04_ctl01$/).exists?)
      # These are div tags and  not  links  
      assert(ie.div(:id, /ctl00_ctl01$/).exists?)
      assert(ie.div(:id, /ctl03_ctl00_ctl02$/).exists?)
      assert(ie.div(:id, /ctl04_ctl00_ctl01$/).exists?)
      #assert(ie.link(:id, /ctl00_TitleBarSearchButton$/).exists?)
      # this is a button
     assert(ie.button(:id, /ctl00_TitleBarSearchButton$/).exists?)
      #assert(ie.link(:id, /ctl00_TitleBarSearchButton$/).exists?)
      assert(ie.link(:text, 'Sample Forum Post').exists?)
      assert(ie.link(:text, 'Last Post').exists?)
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:text, 'More Options').exists?)
    end
    
    def test_08_verifyDropdownListsOnForumPage
      assert(ie.select_list(:id, /SortBy$/).exists?)
      assert(ie.select_list(:id, /SortOrder$/).exists?)
      assert(ie.select_list(:id, /DateFilter$/).exists?)
      assert(ie.select_list(:id, /HideRead$/).exists?)
      assert(ie.select_list(:id, /UserFilter$/).exists?)
      assert(ie.select_list(:id, /Email$/).exists?)
    end
    
    def test_09_verifyCheckBoxesOnForumPage
      assert(ie.checkbox(:name, 'ThreadCheckBox').exists?)
    end
    
    def test_10_verifyButtonsOnForumPage
      assert(ie.button(:id, /ApplyTemp$/).exists?)
      assert(ie.button(:id, /Apply$/).exists?)
      assert(ie.button(:id, /MarkAllRead$/).exists?)
    end
    
    def test_11_verifyFieldsOnForumPage
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
    end
    
    def test_12_selectSampleForumPost
      assert(ie.link(:text, 'Sample Forum Post').exists?)
      ie.link(:text, 'Sample Forum Post').click
     
      assert(ie.contains_text("Sample Forum Post"))
    end
    
    def test_13_verifyLinkButtonsOnForumPostPage
      assert(ie.link(:text, 'Reply').exists?)
      assert(ie.link(:text, 'Report abuse').exists?)
      assert(ie.link(:text, 'Delete').exists?)
      assert(ie.link(:text, 'Edit').exists?)
      assert(ie.link(:text, 'Favorites').exists?)
      assert(ie.link(:text, 'Contact').exists?)
      assert(ie.link(:text, 'Moderate').exists?)
      assert(ie.link(:text, 'Previous').exists?)
      assert(ie.link(:text, 'Next').exists?)
      #assert(ie.link(:text, 'Quick Reply').exists?)
    end
    
    def test_14_addPostAsFavorite
      ie.link(:text, 'Favorites').click
      sleep 5
      
      assert(ie.cell(:text, 'Add admin as a friend').exists?)
      assert(ie.cell(:text, 'Add this post as a favorite').exists?)
      assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
      
       
      ie.cell(:text, 'Add this post as a favorite').click      
    end
    
    def test_15_verifyPostAddedAsFavorite
      ie.link(:text, 'Favorites').click
      
      sleep 5
      
      assert(ie.cell(:text, 'Add admin as a friend').exists?)
      assert(ie.cell(:text, 'Remove this post from favorites').exists?)
      assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
    end
    
    def test_16_addForumAsFavorite
      ie.cell(:text, 'Add this forum as a favorite').click
      
      ie.link(:text, 'Favorites').click
      
      sleep 5
      
      assert(ie.cell(:text, 'Add admin as a friend').exists?)
      assert(ie.cell(:text, 'Remove this post from favorites').exists?)
      assert(ie.cell(:text, 'Remove this forum from favorites').exists?)
    end
    
    def test_17_removeFavorites
      
      ie.cell(:text, 'Remove this forum from favorites').click
      
      ie.link(:text, 'Favorites').click      
      
      sleep 5
      
      ie.cell(:text, 'Remove this post from favorites').click
      
      ie.link(:text, 'Favorites').click
      
      sleep 5
      
      
      assert(ie.cell(:text, 'Add admin as a friend').exists?)
      assert(ie.cell(:text, 'Add this post as a favorite').exists?)
      assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
    end
    
    def test_99_closeIE
      ie.close
    end
    
  end